﻿@using Entity.ProjectEnt;
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Form.cshtml";
    GudaoCarEntity thisobj = ViewData["objs"] as GudaoCarEntity;
    if (thisobj == null)
    {
        thisobj = new GudaoCarEntity();
    }
    List<CustomerAndThingsNameEntity> thingsNameObjList = ViewData["ThingsName"] as List<CustomerAndThingsNameEntity>;
    List<CustomerAndThingsNameEntity> customersObjList = ViewData["Customers"] as List<CustomerAndThingsNameEntity>;
    List<CarTypeEntity> carTypes = ViewData["CarTypes"] as List<CarTypeEntity>;
}

<style>
    .form .formTitle {
        width: 150px !important;
    }

    .layui-layer {
        width: 1500px !important;
    }
</style>
<script>
    var keyValue = $.request("keyValue");
    $(function () {
        if (!!keyValue) {
            $.ajax({
                url: "/Project/GudaoCar/GetFormJson",
                data: { keyValue: keyValue },
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#form1").formSerialize(data);
                }
            });
        }
        else {
            $("#form1").formSerialize("add");
        }

    });

    function submitForm() {

        if (!$('#form1').formValid()) {
            return false;
        }
        $.submitFormAndCloseWin({
            url: "/Project/GudaoCar/SubmitForm?keyValue=" + keyValue + "&Capacity=" + $("#Capacity").val() + "&carType=" + $("#CarType").val+"&CarriageID="+$("#CarriageID").val(),
            param: $("#form1").formSerialize(),
            close: true,
            success: function () {
                //$.currentWindow().$("#gridList").trigger("reloadGrid");
            }  
        });
    }

    function OnRecovery() {
        $.modalConfirm("确定要卸后利用吗？",
            function (r) {
                if (r) {
                    $.submitForm({
                        url: "/Project/GudaoCar/OnRecovery",
                        param: { keyValue: keyValue },
                        close: false,
                        success: function () {
                            $.reload();
                            
                        }
                    });
                }
            });
    }
</script>
<style>
    .recoveryBtn {
        margin-left: 82%;
        background-color: green;
        width: 80px;
        height: 27px;
        border: 0;
        color: white;
    }
    .recoveryBtn2 {
        margin-left: 82%;
        background-color:red;
        width: 80px;
        height: 27px;
        border: 0;
        color: white;
    }
</style>
<form id="form1">
    <div style="margin-top: 10px; margin-left: 10px; margin-right: 10px;">
        <ul class="nav nav-tabs">
            <li class="active"><a href="#">基本信息</a></li>
            @*<li ><a href="#">扩展信息</a></li>*@
        </ul>
        <div style="padding-top: 20px; margin-right: 30px;">
            <table class="form">
                <tr>
                    <th class="formTitle">车号</th>
                    <td class="formValue">
                        @{
                            <input id="CarriageID" name="CarriageID" type="text" class="form-control required" placeholder="请输入车号" value="@(thisobj.BelongCarriage == null ? "" : thisobj.BelongCarriage.CarriageID)" />
                                                                                                                            
                        }
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">车型</th>
                    <td class="formValue">
                        <select id="CarType" name="CarType" style="width: 100%; height: 30px">
                            @{
                                if (carTypes != null && carTypes.Count > 0)
                                {
                                    foreach (var item in carTypes)
                                    {
                                        if (thisobj.BelongCarriage!=null&&thisobj.BelongCarriage.CarType == item.Name)
                                        {
                                            <option value=@item.Name selected="selected">@item.Name</option>
                                        }
                                        else
                                        {
                                            <option value=@item.Name>@item.Name</option>
                                        }

                                    }
                                }
                                @*<input id="CarType" name="CarType" type="text" class="form-control required" placeholder="请输入车型" value="@(thisobj.BelongCarriage == null ? "" : thisobj.BelongCarriage.CarType)" />*@
                            }
                        </select>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">到站时间</th>
                    <td class="formValue">
                        @{

                            <input id="ArriveDateTime" name="ArriveDateTime" type="text" class="form-control required" disabled="disabled" />

                        }
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">载重(吨)</th>
                    <td class="formValue">
                        @{
                            <input id="Capacity" name="Capacity" type="text" class="form-control" placeholder="请输入股道标题" value="@(thisobj.BelongCarriage == null ? "" : thisobj.BelongCarriage.Capacity.ToString())" />
                        }
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">品名</th>
                    <td class="formValue">
                        <select id="ThingsName" name="ThingsName" style="width: 100%; height: 30px">
                            @*<option value=@thisobj.ThingsName>@thisobj.ThingsName</option>*@
                            @{
                                if (thingsNameObjList != null && thingsNameObjList.Count > 0)
                                {
                                    foreach (var item in thingsNameObjList)
                                    {
                                        if (thisobj.ThingsName == item.Name)
                                        {
                                            <option value=@item.Name selected="selected">@item.Name</option>
                                        }
                                        else
                                        {
                                            <option value=@item.Name>@item.Name</option>
                                        }
                                       
                                    }
                                }
                            }
                        </select>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">客户</th>
                    <td class="formValue">
                        <select id="Customers" name="Customers" style="width: 100%; height: 30px">
                            @*<option value=@thisobj.Customers>@thisobj.Customers</option>*@
                            @{
                                if (customersObjList != null && customersObjList.Count > 0)
                                {
                                    foreach (var item in customersObjList)
                                    {
                                        if (thisobj.Customers == item.Name)
                                        {
                                            <option value=@item.Name selected="selected">@item.Name</option>
                                        }
                                        else
                                        {
                                            <option value=@item.Name>@item.Name</option>
                                        }

                                    }
                                }
                            }
                        </select>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">封号</th>
                    <td class="formValue">
                        @{

                            <input id="Fenhao" name="Fenhao" type="text" class="form-control  " placeholder="请输入封号" />

                        }
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">件数</th>
                    <td class="formValue">
                        @{

                            <input id="UnitNumber" name="UnitNumber" type="text" class="form-control  number" placeholder="请输入件数" />

                        }
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">重量(吨)</th>
                    <td class="formValue">
                        @{

                            <input id="Weight" name="Weight" type="text" class="form-control required number" placeholder="请输入重量" />

                        }
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">到站</th>
                    <td class="formValue">
                        @{
                            <input id="ArriveStation" name="ArriveStation" type="text" class="form-control" placeholder="请输入到站" />
                        }
                    </td>
                </tr>

                <tr>
                    <th class="formTitle">备注</th>
                    <td class="formValue">
                        @{
                            <input id="Remark" name="Remark" type="text" class="form-control " placeholder="请输入备注" />
                        }
                    </td>
                </tr>

            </table>
            @{
                if (thisobj.IsRecovery == true)
                {
                    <input type="button" id="Recovery" value="卸后利用" class="recoveryBtn2" disabled="disabled"/>
                }
                else
                {
                    <input type="button" id="Recovery" onclick="OnRecovery()" value="卸后利用" class="recoveryBtn" />
                }
            }
           
        </div>
    </div>
</form>


